/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.sensor.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import nl.cloudfarming.sensor.ParsedUnit;

/**
 * @author I. de Vries
 */
@Entity
@Table(name = "GEOSENSORDATA")
public class GeoSensorDataBO implements Serializable , ParsedUnit{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "GEOSENSORDATA_ID")
    private long geoSensorDataId;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "geoDataFileId")
    private GeoSensorDataFileBO geoDataSensorFile;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "sensorRunId")
    private SensorRunBO sensorRun;

    private double longtitude;

    private double latitude;

    @Column(name = "FIX_TYPE")
    private int fixType;

    @Column(name = "UTC_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date utcTime;

    private double speed;

    private double course;

    private double sensor;

    private double vi1;

    private double vi2;

    private double r1;

    private double r2;

    private double r3;

    @Column(name="APP_RATE")
    private String appRate; //  NOT USED ?

    /**
     * For JPA use only.
     */
    @Deprecated
    protected GeoSensorDataBO() {
    }

    /**
     * Constructor for creating a GeoSensorDataBO
     */
    public GeoSensorDataBO(GeoSensorDataFileBO geoDataSensorFile, double longtitude, double latitude, Integer fixType, Date utcTime,
            double speed, double course, double sensor, double vi1, double vi2, double r1, double r2, double r3, String appRate) {
        setGeoDataSensorFile(geoDataSensorFile);
        this.longtitude = longtitude;
        this.latitude = latitude;
        this.fixType = fixType;
        this.utcTime = utcTime;
        this.speed = speed;
        this.course = course;
        this.sensor = sensor;
        this.vi1 = vi1;
        this.vi2 = vi2;
        this.r1 = r1;
        this.r2 = r2;
        this.r3 = r3;
        this.appRate = appRate;
        //
        if (geoDataSensorFile != null) {
            geoDataSensorFile.addGeoSensorData(this);
        }
    }

    public String getAppRate() {
        return appRate;
    }

    public void setAppRate(String appRate) {
        this.appRate = appRate;
    }

    public double getCourse() {
        return course;
    }

    public void setCourse(double course) {
        this.course = course;
    }

    public Integer getFixType() {
        return fixType;
    }

    public void setFixType(Integer fixType) {
        this.fixType = fixType;
    }

    public GeoSensorDataFileBO getGeoDataSensorFile() {
        return geoDataSensorFile;
    }

    public void setGeoDataSensorFile(GeoSensorDataFileBO geoDataSensorFile) {
        this.geoDataSensorFile = geoDataSensorFile;
    }

    public long getGeoSensorDataId() {
        return geoSensorDataId;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongtitude() {
        return longtitude;
    }

    public void setLongtitude(double longtitude) {
        this.longtitude = longtitude;
    }

    public double getR1() {
        return r1;
    }

    public void setR1(double r1) {
        this.r1 = r1;
    }

    public double getR2() {
        return r2;
    }

    public void setR2(double r2) {
        this.r2 = r2;
    }

    public double getR3() {
        return r3;
    }

    public void setR3(double r3) {
        this.r3 = r3;
    }

    public double getSensor() {
        return sensor;
    }

    public void setSensor(double sensor) {
        this.sensor = sensor;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public Date getUtcTime() {
        return utcTime;
    }

    public void setUtcTime(Date utcTime) {
        this.utcTime = utcTime;
    }

    public double getVi1() {
        return vi1;
    }

    public void setVi1(double vi1) {
        this.vi1 = vi1;
    }

    public double getVi2() {
        return vi2;
    }

    public void setVi2(double vi2) {
        this.vi2 = vi2;
    }

    public SensorRunBO getSensorRunBO() {
        return this.sensorRun;
    }

    public void setSensorRunBO(SensorRunBO sensorRunBO) {
        this.sensorRun = sensorRunBO;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final GeoSensorDataBO other = (GeoSensorDataBO) obj;
        if (this.geoSensorDataId != other.geoSensorDataId) {
            return false;
        }
        if (this.geoDataSensorFile != other.geoDataSensorFile && (this.geoDataSensorFile == null || !this.geoDataSensorFile.equals(other.geoDataSensorFile))) {
            return false;
        }
        if (this.sensorRun != other.sensorRun && (this.sensorRun == null || !this.sensorRun.equals(other.sensorRun))) {
            return false;
        }
        if (Double.doubleToLongBits(this.longtitude) != Double.doubleToLongBits(other.longtitude)) {
            return false;
        }
        if (Double.doubleToLongBits(this.latitude) != Double.doubleToLongBits(other.latitude)) {
            return false;
        }
        if (this.fixType != other.fixType) {
            return false;
        }
        if (this.utcTime != other.utcTime && (this.utcTime == null || !this.utcTime.equals(other.utcTime))) {
            return false;
        }
        if (Double.doubleToLongBits(this.speed) != Double.doubleToLongBits(other.speed)) {
            return false;
        }
        if (Double.doubleToLongBits(this.course) != Double.doubleToLongBits(other.course)) {
            return false;
        }
        if (Double.doubleToLongBits(this.sensor) != Double.doubleToLongBits(other.sensor)) {
            return false;
        }
        if (Double.doubleToLongBits(this.vi1) != Double.doubleToLongBits(other.vi1)) {
            return false;
        }
        if (Double.doubleToLongBits(this.vi2) != Double.doubleToLongBits(other.vi2)) {
            return false;
        }
        if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {
            return false;
        }
        if (Double.doubleToLongBits(this.r2) != Double.doubleToLongBits(other.r2)) {
            return false;
        }
        if (Double.doubleToLongBits(this.r3) != Double.doubleToLongBits(other.r3)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + (int) (this.geoSensorDataId ^ (this.geoSensorDataId >>> 32));
        hash = 41 * hash + (this.geoDataSensorFile != null ? this.geoDataSensorFile.hashCode() : 0);
        hash = 41 * hash + (this.sensorRun != null ? this.sensorRun.hashCode() : 0);
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.longtitude) ^ (Double.doubleToLongBits(this.longtitude) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.latitude) ^ (Double.doubleToLongBits(this.latitude) >>> 32));
        hash = 41 * hash + this.fixType;
        hash = 41 * hash + (this.utcTime != null ? this.utcTime.hashCode() : 0);
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.speed) ^ (Double.doubleToLongBits(this.speed) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.course) ^ (Double.doubleToLongBits(this.course) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.sensor) ^ (Double.doubleToLongBits(this.sensor) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.vi1) ^ (Double.doubleToLongBits(this.vi1) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.vi2) ^ (Double.doubleToLongBits(this.vi2) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.r2) ^ (Double.doubleToLongBits(this.r2) >>> 32));
        hash = 41 * hash + (int) (Double.doubleToLongBits(this.r3) ^ (Double.doubleToLongBits(this.r3) >>> 32));
        return hash;
    }

  

}
